/*    */ package blockbuster.components.expiration;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.components.IComponentParticleUpdate;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.emitter.BedrockParticle;
/*    */ import blockbuster.math.Operation;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import com.google.gson.JsonArray;
/*    */ import com.google.gson.JsonElement;
/*    */ import javax.vecmath.Tuple3d;
/*    */ import javax.vecmath.Vector3d;
/*    */ 
/*    */ public class BedrockComponentKillPlane
/*    */   extends BedrockComponentBase
/*    */   implements IComponentParticleUpdate
/*    */ {
/*    */   public float a;
/*    */   public float b;
/*    */   public float c;
/*    */   public float d;
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement element, MolangParser parser) throws MolangException {
/* 25 */     if (!element.isJsonArray())
/*    */     {
/* 27 */       return super.fromJson(element, parser);
/*    */     }
/*    */     
/* 30 */     JsonArray array = element.getAsJsonArray();
/*    */     
/* 32 */     if (array.size() >= 4) {
/*    */       
/* 34 */       this.a = array.get(0).getAsFloat();
/* 35 */       this.b = array.get(1).getAsFloat();
/* 36 */       this.c = array.get(2).getAsFloat();
/* 37 */       this.d = array.get(3).getAsFloat();
/*    */     } 
/*    */     
/* 40 */     return super.fromJson(element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 46 */     JsonArray array = new JsonArray();
/*    */     
/* 48 */     if (Operation.equals(this.a, 0.0D) && Operation.equals(this.b, 0.0D) && Operation.equals(this.c, 0.0D) && Operation.equals(this.d, 0.0D))
/*    */     {
/* 50 */       return (JsonElement)array;
/*    */     }
/*    */     
/* 53 */     array.add(Float.valueOf(this.a));
/* 54 */     array.add(Float.valueOf(this.b));
/* 55 */     array.add(Float.valueOf(this.c));
/* 56 */     array.add(Float.valueOf(this.d));
/*    */     
/* 58 */     return (JsonElement)array;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void update(BedrockEmitter emitter, BedrockParticle particle) {
/* 64 */     if (particle.dead) {
/*    */       return;
/*    */     }
/*    */ 
/*    */     
/* 69 */     Vector3d prevLocal = new Vector3d(particle.prevPosition);
/* 70 */     Vector3d local = new Vector3d(particle.position);
/*    */     
/* 72 */     if (!particle.relativePosition) {
/*    */       
/* 74 */       local.sub((Tuple3d)emitter.lastGlobal);
/* 75 */       prevLocal.sub((Tuple3d)emitter.lastGlobal);
/*    */     } 
/*    */     
/* 78 */     double prev = this.a * prevLocal.x + this.b * prevLocal.y + this.c * prevLocal.z + this.d;
/* 79 */     double now = this.a * local.x + this.b * local.y + this.c * local.z + this.d;
/*    */     
/* 81 */     if ((prev > 0.0D && now < 0.0D) || (prev < 0.0D && now > 0.0D))
/*    */     {
/* 83 */       particle.dead = true;
/*    */     }
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public int getSortingIndex() {
/* 90 */     return 100;
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\expiration\BedrockComponentKillPlane.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */